package com.atguigu.tingshu.user.strategy.factory;

import com.atguigu.tingshu.user.strategy.PaidRecordStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: atguigu
 * @create: 2024-05-25 15:25
 */
@Slf4j
@Component
public class StrategyFactory {


    /**
     * Spring进行注入，通过Map接收注入Bean
     * Map中Key：IOC容器中策略实现类BeanID
     * Map中Value：不同策略实现类对象
     */
    @Autowired
    private Map<String, PaidRecordStrategy> strategyMap;


    /**
     * 根据传入购买项目类型返回具体实现类对象
     *
     * @param itemType
     * @return
     */
    public PaidRecordStrategy getStrategyByItemType(String itemType) {
        if (strategyMap.containsKey(itemType)) {
            return strategyMap.get(itemType);
        }
        log.error("该购买项目类型暂不支持处理");
        return null;
    }


}
